package com.zzq.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.zzq.domain.dto.SmilePhotographerDTO;
import com.zzq.domain.dto.SmilePhotographerKpiDTO;
import com.zzq.domain.entity.SmilePhotographer;
import com.zzq.domain.search.PhotographerSearchParamet;
import com.zzq.mapper.SmilePhotographerMapper;
import com.zzq.service.SmilePhotographerService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.zzq.util.ObjectUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 谢文宗
 * @since 2023-08-22
 */
@Service
public class SmilePhotographerServiceImpl extends ServiceImpl<SmilePhotographerMapper, SmilePhotographer> implements SmilePhotographerService {

    @Autowired
    SmilePhotographerMapper photographerMapper;
    @Override
    public List<SmilePhotographerDTO> getPhotographerDTOList(PhotographerSearchParamet photographerSearchParamet) {
        return photographerMapper.getPhotographerDTOList(photographerSearchParamet);
    }

    @Override
    public SmilePhotographer getPhotographerByRegisteReferralCode(String registerReferralCode) {
        LambdaQueryWrapper<SmilePhotographer>  queryWrapper=new LambdaQueryWrapper<>();
        queryWrapper.eq(SmilePhotographer::getReferralCode,registerReferralCode);
        SmilePhotographer smilePhotographer = photographerMapper.selectOne(queryWrapper);
        return smilePhotographer;
    }

    @Override
    public SmilePhotographer getPhotographerByReferredPhotographerId(Long photographerId) {
        SmilePhotographer smilePhotographer = photographerMapper.selectById(photographerId);
        String registerReferralCode = smilePhotographer.getRegisterReferralCode();
        if (ObjectUtils.isEmpty(registerReferralCode)) return null;
        return getPhotographerByRegisteReferralCode(registerReferralCode);
    }

    @Override
    public List<SmilePhotographerKpiDTO> getPhotographerKpiDTOList(PhotographerSearchParamet photographerSearchParamet) {

      return   photographerMapper.getPhotographerKpiDTOList(photographerSearchParamet);
    }
}
